﻿/***********************************************************************************************
 * 
 * ProjectName: WMSSoft.Lib.WinKStart
 * 
 * Description: Contains the configuration a GUI - Element or Elements Property| Event
 * 
 * Created:     13.07.2015
 * 
 * Author:      matthias wagler - matthias@WMSSoft.de
 * 
 * Copyright:   Copyright 2015 by WMSSoft.net
 * 
 * License:     GPLv3
 * 
 * History:     13.07.2015 - matthias wagler matthias@WMSSoft.de   -   Created
 * 
 **********************************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WMSSoft.Lib.Basic;
using WMSSoft.Lib.WinKStart.Model.Metadata;

namespace WMSSoft.Lib.WinKStart.Classes.Metadata
{
    public static class Meta_Elements
    {
        static List<Meta_ElementData> _GUIElements = null;
        static List<Meta_ElementData> _GUIElementProperties = null;
        static List<Meta_ElementData> _GUIElementEvents = null;

        public static void LoadElements() 
        {
            try
            {
                _GUIElements = new List<Meta_ElementData>();

                _GUIElements.Add(new Meta_ElementData("img_UserPicture", LanguageStrings.GetText("User Picture"), "IMAGE"));
                _GUIElements.Add(new Meta_ElementData("lbl_UserName", LanguageStrings.GetText("User Name"), "LABEL PROPERTIES"));
                _GUIElements.Add(new Meta_ElementData("lbl_AppName", LanguageStrings.GetText("Application Name"), "LABEL PROPERTIES"));
                _GUIElements.Add(new Meta_ElementData("img_SearchPicture", LanguageStrings.GetText("Search Picture"), "IMAGE"));
                _GUIElements.Add(new Meta_ElementData("lbl_Search", LanguageStrings.GetText("Search Label"), "LABEL PROPERTIES"));
                _GUIElements.Add(new Meta_ElementData("txt_ProgramSearchbox", LanguageStrings.GetText("Search Text"), "TEXTBOX PROPERTIES"));
                _GUIElements.Add(new Meta_ElementData("SelectedItem", LanguageStrings.GetText("Current selected List-Item"), "LISTITEM PROPERTIES"));
                _GUIElements.Add(new Meta_ElementData("pan_ButtonsHost", LanguageStrings.GetText("Region Selector"), "SELECTOR PROPERTIES"));
                _GUIElements.Add(new Meta_ElementData("img_SelectNextButtons", LanguageStrings.GetText("Next Region Button View"), "BUTTON PROPERTIES"));
                _GUIElements.Add(new Meta_ElementData("img_SelectPreviousButtons", LanguageStrings.GetText("Previous Region Button View"), "BUTTON PROPERTIES"));

                _GUIElementProperties = new List<Meta_ElementData>();
                _GUIElementProperties.Add(new Meta_ElementData("LinkFilename", LanguageStrings.GetText("LinkFilename (Executable Name)"), "LISTITEM"));
                _GUIElementProperties.Add(new Meta_ElementData("Arguments", LanguageStrings.GetText("Arguments (Application Arguments)"), "LISTITEM"));
                _GUIElementProperties.Add(new Meta_ElementData("ItemName", LanguageStrings.GetText("Name (Name Selected Item)"), "LISTITEM"));
                _GUIElementProperties.Add(new Meta_ElementData("ContentType", LanguageStrings.GetText("Type (Type Selected Item)"), "LISTITEM"));
                _GUIElementProperties.Add(new Meta_ElementData("Text", LanguageStrings.GetText("Text (Entered Text)"), "TEXTBOX"));
                _GUIElementProperties.Add(new Meta_ElementData("ItemIndex", LanguageStrings.GetText("ItemIndex (Index selected Region)"), "SELECTOR"));
                _GUIElementProperties.Add(new Meta_ElementData("ItemName", LanguageStrings.GetText("Name (Name selected Region)"), "SELECTOR"));
                _GUIElementProperties.Add(new Meta_ElementData("Caption", LanguageStrings.GetText("Caption (In Element viewed Text)"), "LABEL"));
                _GUIElementProperties.Add(new Meta_ElementData("Caption", LanguageStrings.GetText("Caption (In Button viewed Text)"), "BUTTON"));

                _GUIElementEvents = new List<Meta_ElementData>();
                _GUIElementEvents.Add(new Meta_ElementData("Click", LanguageStrings.GetText("Click"), "CONTEXTMENU"));

                _GUIElementEvents.Add(new Meta_ElementData("TextChanged", LanguageStrings.GetText("TextChanged (Text was changed)"), "TEXTBOX"));
                _GUIElementEvents.Add(new Meta_ElementData("MouseUp", LanguageStrings.GetText("MouseUp (Release Mouse Button)"), "TEXTBOX"));
                _GUIElementEvents.Add(new Meta_ElementData("KeyUp", LanguageStrings.GetText("KeyUp (Release Keyboard Button)"), "TEXTBOX"));
                _GUIElementEvents.Add(new Meta_ElementData("GotFocus", LanguageStrings.GetText("GotFocus (Set as Active Element)"), "TEXTBOX"));
                _GUIElementEvents.Add(new Meta_ElementData("LostFocus", LanguageStrings.GetText("LostFocus (Lost Active state)"), "TEXTBOX"));
                _GUIElementEvents.Add(new Meta_ElementData("MouseEnter", LanguageStrings.GetText("MouseEnter (Mouse enter Element)"), "TEXTBOX"));
                _GUIElementEvents.Add(new Meta_ElementData("MouseLeave", LanguageStrings.GetText("MouseLeave (Mouse leave Element)"), "TEXTBOX"));

                _GUIElementEvents.Add(new Meta_ElementData("MouseUp", LanguageStrings.GetText("MouseUp (Release Mouse Button)"), "LABEL"));
                _GUIElementEvents.Add(new Meta_ElementData("MouseEnter", LanguageStrings.GetText("MouseEnter (Mouse enter Element)"), "LABEL"));
                _GUIElementEvents.Add(new Meta_ElementData("MouseLeave", LanguageStrings.GetText("MouseLeave (Mouse leave Element)"), "LABEL"));

                _GUIElementEvents.Add(new Meta_ElementData("MouseUp", LanguageStrings.GetText("MouseUp (Release Mouse Button)"), "LISTITEM"));

                _GUIElementEvents.Add(new Meta_ElementData("MouseUp", LanguageStrings.GetText("MouseUp (Release Mouse Button)"), "SELECTOR"));
                _GUIElementEvents.Add(new Meta_ElementData("MouseEnter", LanguageStrings.GetText("MouseEnter (Mouse enter Element)"), "SELECTOR"));
                _GUIElementEvents.Add(new Meta_ElementData("MouseLeave", LanguageStrings.GetText("MouseLeave (Mouse leave Element)"), "SELECTOR"));

                _GUIElementEvents.Add(new Meta_ElementData("MouseUp", LanguageStrings.GetText("MouseUp (Release Mouse Button)"), "IMAGE"));
                _GUIElementEvents.Add(new Meta_ElementData("MouseEnter", LanguageStrings.GetText("MouseEnter (Mouse enter Element)"), "IMAGE"));
                _GUIElementEvents.Add(new Meta_ElementData("MouseLeave", LanguageStrings.GetText("MouseLeave (Mouse leave Element)"), "IMAGE"));

                _GUIElementEvents.Add(new Meta_ElementData("MouseUp", LanguageStrings.GetText("MouseUp (Release Mouse Button)"), "BUTTON"));
                _GUIElementEvents.Add(new Meta_ElementData("KeyUp", LanguageStrings.GetText("Release Keyboard Button"), "BUTTON"));
                _GUIElementEvents.Add(new Meta_ElementData("GotFocus", LanguageStrings.GetText("GotFocus (Set as Active Element)"), "BUTTON"));
                _GUIElementEvents.Add(new Meta_ElementData("LostFocus", LanguageStrings.GetText("LostFocus (Lost Active state)"), "BUTTON"));
                _GUIElementEvents.Add(new Meta_ElementData("MouseEnter", LanguageStrings.GetText("MouseEnter (Mouse enter Element)"), "BUTTON"));
                _GUIElementEvents.Add(new Meta_ElementData("MouseLeave", LanguageStrings.GetText("MouseLeave (Mouse leave Element)"), "BUTTON"));
            }
            catch (Exception Ex) 
            {
                CMessagelogging.AppendMessage("Error while initializing GUI-Meta-Elements", Ex, EMessageTypes.Error);
            }
        }

        public static List<KeyValueAssignment> GetGUIElements(string Type)
        {
            try
            {
                List<Meta_ElementData> tmpResult = null;

                if (Type.ToUpper() != "ALL")
                    tmpResult = (from Item in _GUIElements where Item.Type.Contains(Type.ToUpper()) select Item).ToList();
                else
                    tmpResult = _GUIElements;

                List<KeyValueAssignment> tmpResultList = new List<KeyValueAssignment>();
                tmpResultList.Add(new KeyValueAssignment("", LanguageStrings.GetText("Please choose a Element")));

                foreach (Meta_ElementData Item in tmpResult)
                {
                    tmpResultList.Add(new KeyValueAssignment(Item.Name, Item.Caption));
                }

                return tmpResultList;
            }
            catch (Exception Ex) 
            {
                throw new Exception("Error while initializing GUI-Meta-Elements", Ex);
            }
        }

        public static Meta_ElementData GetGUIElement(string Name)
        {
            try
            {
                List<Meta_ElementData> tmpResult = (from Item in _GUIElements where Item.Name == Name select Item).ToList();

                if (tmpResult != null && tmpResult.Count() > 0)
                    return tmpResult[0];
                else
                    return null;
            }
            catch (Exception Ex)
            {
                throw new Exception("Unable to Get GUI-Element Meta-Data", Ex);
            }
        }

        public static List<KeyValueAssignment> GetGUIElementProperties(string Name)
        {
            try
            {
                Meta_ElementData tmpGUIObject = GetGUIElement(Name);

                string tmpElementType = tmpGUIObject.Type;
                if (tmpElementType.Contains(" ") == true)
                {
                    int tmpWhiteSpacePos = tmpElementType.IndexOf(" ");
                    tmpElementType = tmpElementType.Substring(0,tmpWhiteSpacePos);
                }

                List<Meta_ElementData> tmpResult = (from Item in _GUIElementProperties where Item.Type == tmpElementType select Item).ToList();

                List<KeyValueAssignment> oResult = new List<KeyValueAssignment>();

                oResult.Add(new KeyValueAssignment("", LanguageStrings.GetText("Please choose a Property")));

                foreach (Meta_ElementData PropertyItem in tmpResult)
                {
                    oResult.Add(new KeyValueAssignment(PropertyItem.Name, PropertyItem.Caption));
                }

                return oResult;
            }
            catch (Exception Ex)
            {
                throw new Exception("Unable to Get GUI-Element Properties!", Ex);
            }
        }

        public static List<KeyValueAssignment> GetGUIElementEvents(string Name)
        {
            try 
            {
                Meta_ElementData tmpGUIObject = GetGUIElement(Name);

                string tmpElementType = tmpGUIObject.Type;
                if (tmpElementType.Contains(" ") == true)
                {
                    int tmpWhiteSpacePos = tmpElementType.IndexOf(" ");
                    tmpElementType = tmpElementType.Substring(0, tmpWhiteSpacePos);
                }

                List<Meta_ElementData> tmpResult = (from Item in _GUIElementEvents where Item.Type == tmpElementType select Item).ToList();

                List<KeyValueAssignment> oResult = new List<KeyValueAssignment>();

                oResult.Add(new KeyValueAssignment("", LanguageStrings.GetText("Please choose a Event")));

                foreach (Meta_ElementData PropertyItem in tmpResult)
                {
                    oResult.Add(new KeyValueAssignment(PropertyItem.Name, PropertyItem.Caption));
                }

                return oResult;
            }
            catch (Exception Ex)
            {
                throw new Exception("Unable to Get GUI-Element Events!", Ex);
            }
        }

        public static List<KeyValueAssignment> GetTypeEvents(string Type)
        {
            try
            {

                List<Meta_ElementData> tmpResult = (from Item in _GUIElementEvents where Item.Type.ToUpper() == Type.ToUpper() select Item).ToList();

                List<KeyValueAssignment> oResult = new List<KeyValueAssignment>();

                oResult.Add(new KeyValueAssignment("", LanguageStrings.GetText("Please choose a Event")));

                foreach (Meta_ElementData PropertyItem in tmpResult)
                {
                    oResult.Add(new KeyValueAssignment(PropertyItem.Name, PropertyItem.Caption));
                }

                return oResult;
            }
            catch (Exception Ex)
            {
                throw new Exception("Unable to Get GUI-Element Events!", Ex);
            }
        }
    }
}
